package com.ibuonline.b2b.entity;

import java.io.Serializable;

import com.ibuonline.b2b.common.ResourceUtil;

public class ShopDecoration implements Serializable {

	private static final long serialVersionUID = 8077612570507166020L;

	//fields
	private java.lang.Integer companyId;
	private java.lang.String css;
	private java.lang.String layout;
	private java.lang.String banner;
	private java.lang.String bannerType;
	private java.lang.String bannerPos;
	private java.sql.Timestamp lastupdate;

	//default constructor
	public ShopDecoration() {
	}

	//getter
	public java.lang.Integer getCompanyId() {
		return companyId;
	}
	public java.lang.String getCss() {
		return css;
	}
	public java.lang.String getLayout() {
		return layout;
	}
	public java.lang.String getBanner() {
		return banner;
	}
	public java.lang.String getBannerType() {
		return bannerType;
	}
	public java.lang.String getBannerPos() {
		return bannerPos;
	}
	public java.sql.Timestamp getLastupdate() {
		return lastupdate;
	}

	//setter
	public void setCompanyId(java.lang.Integer companyId) {
		this.companyId = companyId;
	}
	public void setCss(java.lang.String css) {
		this.css = css;
	}
	public void setLayout(java.lang.String layout) {
		this.layout = layout;
	}
	public void setBanner(java.lang.String banner) {
		this.banner = banner;
	}
	public void setBannerType(java.lang.String bannerType) {
		this.bannerType = bannerType;
	}
	public void setBannerPos(java.lang.String bannerPos) {
		this.bannerPos = bannerPos;
	}
	public void setLastupdate(java.sql.Timestamp lastupdate) {
		this.lastupdate = lastupdate;
	}

	//equals method
	public boolean equals(Object other) {
		if (this == other)
			return true;
		if (!(other instanceof ShopDecoration))
			return false;

		final ShopDecoration shopDecoration = (ShopDecoration)other;
		if (!this.companyId.equals(shopDecoration.getCompanyId()))
			return false;

		return true;
	}

	//hashCode method
	public int hashCode() {
		StringBuffer keys = new StringBuffer();
		keys.append(companyId).append(",");
		if (keys.length() > 0)
			keys.deleteCharAt(keys.length() - 1);
		return keys.toString().hashCode();
	}

	//toString method
	public String toString() {
		return new StringBuilder("ShopDecoration[")
			.append("companyId=").append(companyId).append(", ")
			.append("css=").append(css).append(", ")
			.append("layout=").append(layout).append(", ")
			.append("banner=").append(banner).append(", ")
			.append("bannerType=").append(bannerType).append(", ")
			.append("bannerPos=").append(bannerPos).append(", ")
			.append("lastupdate=").append(lastupdate).append("]").toString();
	}
	
	///################
	private String templateName;
	private String templatePic;
	private String layoutCss;
	private String bannerPic;
	private String bannerName;
	
	public String getBannerUrl() {
		if("2".equals(bannerType)) {
			String[] temp = banner.split(";");
			String url = "";
    		for (int i = 0;i<temp.length;i++) {
    			String[] bannerUrl = temp[i].split(":");
    			if(bannerUrl.length == 2) {
    				url += ResourceUtil.getResPath(bannerUrl[1]) + ",";
    			}
    		}
			return url.substring(0, url.lastIndexOf(","));
		} else if("3".equals(bannerType)) {
			return ResourceUtil.getResPath(banner);
		}
		return banner+".jpg";
	}
	
	public String getInitShowBanner() {
		if("1".equals(bannerType)) {
			return "http://img1.taojindi.com/sba/"+banner+".jpg";
		} else if("2".equals(bannerType)) {
			String[] temp = banner.split(";");
			String[] url = temp[0].split(":");
			if(url.length == 2) {
				return ResourceUtil.getResPath(url[1]);
			}
		} 
		return "";
	}
	
	public String getTemplateName() {
		return templateName;
	}

	public void setTemplateName(String templateName) {
		this.templateName = templateName;
	}

	public String getTemplatePic() {
		return templatePic;
	}

	public void setTemplatePic(String templatePic) {
		this.templatePic = templatePic;
	}

	public String getLayoutCss() {
		return layoutCss;
	}

	public void setLayoutCss(String layoutCss) {
		this.layoutCss = layoutCss;
	}

	public String getBannerPic() {
		return bannerPic;
	}

	public void setBannerPic(String bannerPic) {
		this.bannerPic = bannerPic;
	}

	public String getBannerName() {
		return bannerName;
	}

	public void setBannerName(String bannerName) {
		this.bannerName = bannerName;
	}
}